namespace Microsoft.ServiceModel.Samples.Discovery.Protocol
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;
    using System.ServiceModel;

    
    [XmlType(Namespace = ProtocolStrings.Namespace)]
    [XmlRoot(ProtocolStrings.ResolveMatchElement,
        Namespace = ProtocolStrings.Namespace)]
    public class ResolveMatch : ServiceProperties
    {
        public static ResolveMatch FromServiceProperties(
            ServiceProperties serviceProperties)
        {
            if (serviceProperties == null)
                throw new ArgumentNullException("serviceProperties");

            ResolveMatch resolveMatch = new ResolveMatch();

            resolveMatch.EndpointAddress = serviceProperties.EndpointAddress;
            resolveMatch.MetadataVersion = serviceProperties.MetadataVersion;
            resolveMatch.Types = serviceProperties.Types;
            resolveMatch.Scopes = serviceProperties.Scopes;
            resolveMatch.XAddrs = serviceProperties.XAddrs;
            resolveMatch.AnyElements = serviceProperties.AnyElements;
            resolveMatch.AnyAttributes = serviceProperties.AnyAttributes;

            return resolveMatch;
        }

        public bool IsValid()
        {
            return (
                (this.EndpointAddress != null) && 
                (this.XAddrs != null) && 
                (this.XAddrs.Count > 0));
        }
    }
}
